import {Component} from 'react'
import {View, Text} from '@tarojs/components'
import {AtButton, AtAvatar} from 'taro-ui'
import "taro-ui/dist/style/components/button.scss" // 按需引入
import './index.less'
import TabBar from "../../common/taBar";


//电子病历
import Taro from '@tarojs/taro';


export default class Index extends Component {
  state = {//内置变量
    name: 'zhangsan',
    dataList: [],
    code:''
  }

  shouldComponentUpdate(nextProps, nextState) {//更改即将发生时候执行
    if (nextState.name == 'lisi')
      return true
    else
      return false;//表示该更改state变量的动作失效
  }

  componentWillMount() {
    this.setState({
      code:''
    })
    Taro.getStorage({
      key: '__itemcode__',
      success: (res) => {
        const itemcode = res.data;
        Taro.request({
          url: `http://http://127.0.0.1:80/myRecord/findAllMedicalRecords?code=`+this.state.code,
          header: {
            'content-type': 'application/json' // 默认值
          },
          method: 'GET',
          dataType: 'json',
          credentials: 'include',
          success: (res) => {
            this.setState({
              dataList: res.data.data
            })
          },
          fail: function (errMsg) {
            Taro.showToast({
              title: '服务器请求失败!',
              icon: 'none',
              duration: 3000
            })
          }
        });
      }
    })
  }


  render() {
    let dataList = this.state.dataList
    return (
      <View className='index'>

        <view className='table-card'>
          <view className='patien-name'><Text>患者姓名：</Text><Text>赵语</Text></view>
          <View className='at-row title'>
            <View className='at-col'>患者姓名</View>
            <View className='at-col'>就诊日期</View>
            <View className='at-col'>操作</View>
          </View>
          <View className='at-row table-td-wi'>
            <View className='at-col'>赵语</View>
            <View className='at-col'>2021-08-10</View>
            <View className='at-col'><Text>查看</Text></View>
          </View>
          <View className='at-row table-td-hu'>
            <View className='at-col'>赵语</View>
            <View className='at-col'>2021-08-10</View>
            <View className='at-col'><Text>查看</Text></View>
          </View>
        </view>

        <view className='table-card'>
          <view className='patien-name'><Text>患者姓名：</Text><Text>赵语</Text></view>
          <View className='at-row title'>
            <View className='at-col'>患者姓名</View>
            <View className='at-col'>就诊日期</View>
            <View className='at-col'>操作</View>
          </View>
          {
            dataList.map((data, index) => {
              return <View className='at-row table-td-wi'>
                <View className='at-col'>赵语</View>
                <View className='at-col'>{data.visitDtime}</View>
                <View className='at-col'><Text>查看</Text></View>
              </View>
            })
          }
        </view>
        <TabBar tabBarCurrent={3}/>
      </View>
    )
  }
}
